<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>
      // axios返回的就是一个promise
      //   const res = axios({
      //     url: 'http://ajax-api.itheima.net/api/news',
      //   })
      //     .then()
      //     .catch()
      //   console.log(res)

      // promise原生的写法
      const p = new Promise(function (resolve, reject) {
        // 请求成功了
        setTimeout(() => {
          console.log('异步执行完了')
          resolve('成功了')
        }, 1000)
        // resolve('成功了')
        // 请求失败
        // reject('失败了')
      })
        .then((res) => {
          console.log('res', res)
        })
        .catch((err) => console.log('err', err))

      console.log(p)
    </script>
  </body>
</html>
